<template>
  <el-dialog title="添加班级" :visible.sync="isAddClass" width="30%" :before-close="handleClose" :close-on-click-modal='false'>
    <el-form ref="form" :model="form" label-width="80px" size="small">
      <el-row>
        <el-col :span="20">
          <el-form-item label="班级名称">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <p style="line-height:33px">&nbsp;班</p>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close()">取 消</el-button>
      <el-button type="primary" @click="checkFn()">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {APIADDCLASS} from '@/common/api.js'
export default {
  props: ['isAddClass', 'row'],
  data () {
    return {
      form: {
      }
    }
  },
  methods: {
    handleClose () {
      this.$emit('noAddClass')
    },
    close (type) {
      this.$emit('noAddClass', type)
    },
    checkFn () {
      if (this.form.section_title === '') {
        this.$message.warning('班级名称不能为空')
        return false
      }
      this.submit()
    },
    submit () { // 提交
      APIADDCLASS({
        grade_id: this.row.id,
        class_title: this.form.name + '班'
      }).then((res) => {
        if (res.status === 1) {
          this.$message.success(res.msg)
          this.close(1)
        } else {
          this.$message.error(res.msg)
        }
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
